<?php
/**
 * @package quizzes
 * @author Andrew Meredith <andymeredith@gmail.com>
 */
namespace PhpQuizzes\Database;

/**
 * This class is responsible for getting Quizzes from the database and saving them
 */
class QuizSerializer {
	private static $_instance;
	
	/**
	 * This singleton's constructor is inaccessible to the outside world
	 */
	private static function __construct() {}
	
	static function instance() {
    	if ( !isset( self::$_instance ) )
      		self::$_instance = new self();
    	return self::$_instance;
  	}
  	
  	/**
  	 * Gets a quiz previously stored in the database
  	 *
  	 * @param int $id
  	 * @return PhpQuizzes\Quiz the Quiz retrieved from the database
  	 */
  	public function get($id) {
  		// Do something
  		return new PhpQuizzes\Quiz();
  	}
  	
  	
  	public function save(PhpQuizzes\Quiz $quiz) {
  		if( $this->isNewRecord($quiz) ) {
  			return $this->create($quiz);
  		} else {
  			return $this->update($quiz);
  		}
  	}
  	
// PRIVATE METHODS

  	private function isNewRecord(PhpQuizzes\Quiz $quiz) {
  		return ($quiz->getId() == null);
  	}
  	
  	/**
  	 * Creates a new Quiz record
  	 *
  	 * @param PhpQuizzes\Quiz $quiz
  	 * @return int|boolean On success, the id of the record created; on failure, boolean <i>false</i>
  	 */
  	private function create(PhpQuizzes\Quiz $quiz) {
  		// Do stuff
  	}
  	
  	/**
  	 * Updates an existing Quiz record
  	 *
  	 * @param PhpQuizzes\Quiz $quiz
  	 * @return int|boolean On success, the id of the record updated; on failure, boolean <i>false</i>
  	 */
  	private function update(PhpQuizzes\Quiz $quiz) {
  		// Do stuff
  	}
  	
  	/**
  	 * Grabs the questions to initialize
  	 * @param unknown_type $id
  	 */
  	private function getQuestionsByQuizId($id) {
  		// Do stuff
  	}
}